﻿<style>
	.tw,#addtw{
		display: none;
	}
</style>
<div class="row">
    <div class="col-xs-12 col-md-12 col-lg-12">
        <div class="widget">
            <div class="widget-header bg-blue">
            	<i class="widget-icon fa fa-arrow-left"></i>
                <span class="widget-caption">关键词回复</span>
                <div class="widget-buttons">
                    <a href="#" data-toggle="maximize">
                        <i class="fa fa-expand"></i>
                    </a>
                    <a href="#" data-toggle="collapse">
                        <i class="fa fa-minus"></i>
                    </a>
                    <a href="#" data-toggle="dispose">
                        <i class="fa fa-times"></i>
                    </a>
                </div>
            </div>
            <div class="widget-body" style="height: auto;">
				
				<div class="form-title">
                    <a href="/Admin/Wx/keyword" class="btn btn-primary" data-loader="bb-loader" data-loadername="自定义菜单">
						<i class="fa fa-mail-reply"></i>返回
					</a>
                </div>
                
                <form id="bbForm" action="" method="post" class="form-horizontal"
                                                  data-bv-message=""
                                                  data-bv-feedbackicons-valid="glyphicon glyphicon-ok"
                                                  data-bv-feedbackicons-invalid="glyphicon glyphicon-remove"
                                                  data-bv-feedbackicons-validating="glyphicon glyphicon-refresh">
                
                <input type="hidden" name="id" value="{$cache.id}">
                <input type="hidden" name="wx_id" value="{$wx_id}">

				<div class="form-group">
				    <label class="col-lg-2 control-label">触发关键词<sup>*</sup></label>
				    <div class="col-lg-4">
				    <input type="text" class="form-control" name="keyword" placeholder="必填"
				                                           data-bv-notempty="true"
				                                           data-bv-notempty-message="不能为空" value="{$cache.keyword}">
				    </div>
				</div>

				 <div class="form-group">
                        <label class="col-lg-2 control-label">关键词类型<sup>*</sup></label>
                        <div class="col-lg-4">
                        		<select id="typechange" name="type" data-bv-field="type">
                        			<option value="text" <eq name="cache.type" value="text" > selected="selected" </eq> >文本［text］</option>
                        			<option value="news" <eq name="cache.type" value="news" > selected="selected" </eq> >图文［news］</option>
                        			<option value="newss" <eq name="cache.type" value="newss" > selected="selected" </eq> >多图文［newss］</option>
                        		</select>
								<a href="javascript:void(0);" id="addtw" class="btn btn-primary">
									<i class="fa fa-plus"></i>增加图文
								</a>
                        </div>
                   </div>
                  
                   <div class="form-group nr">
                        <label class="col-lg-2 control-label">回复内容</label>
                        <div class="col-lg-4">
                        	<textarea class="form-control" name="content">{$cache.content}</textarea>
                        </div>
                   </div>
                   
                  <if condition="$tmp_data">
                      <foreach name="tmp_data" item="vo" key="k" >
                      <hr/>
                      <input type="hidden" name="data[id][]" value="{$vo.id}" >
                      <div class="form-group">
		                    <label class="col-lg-2 control-label">图文标题</label>
		                    <div class="col-lg-4">
		                    	<input type="text" class="form-control" name="data[title][]" value="{$vo.title}" >
		                   </div>
		               </div>
		               <div class="form-group">
		                    <label class="col-lg-2 control-label">图文图片</label>
		                    <div class="col-lg-4">
		                    	<div class="input-group input-group-sm">
		                    		<input type="text" class="form-control" name="data[img][]" id="bb-img" value="{$vo.img}" >
		                    		<span class="input-group-btn">
		                        		<button class="btn btn-default shiny" type="button" onclick="Imgviewer('bb-img')"><i class="fa fa-camera-retro"></i>预览</button><button class="btn btn-default shiny" type="button" onclick="Imguploader('bb-img',false)"><i class="glyphicon glyphicon-picture"></i>上传</button>
		                    		</span>
		                    	</div>
		                    </div>
		              </div>
		               <div class="form-group">
		                    <label class="col-lg-2 control-label">图文详情</label>
		                    <div class="col-lg-4">
		                    	<input type="text" class="form-control" name="data[info][]" value="{$vo.info}" >
		                    </div>
		               </div>
		               <div class="form-group">
		                    <label class="col-lg-2 control-label">图文链接</label>
		                    <div class="col-lg-4">
		                    	<input type="text" class="form-control" name="data[url][]" value="{$vo.url}" >
		                    </div>
		               </div>
					   </foreach> 
                  </if>
                  
                  <div id="dnrdiv">
                  	
                  	
                  </div>
                  
                  <div class="form-group">
                    <div class="col-lg-offset-2 col-lg-4">
                         <button class="btn btn-primary btn-lg" type="submit">保存</button>&nbsp;&nbsp;&nbsp;&nbsp;
                         <button class="btn btn-palegreen btn-lg" type="reset">重填</button>
                    </div>
                  </div>
            </div>
        </div>
    </div>
</div>
<!--面包屑导航封装-->
<div id="tmpbread" style="display: none;">{$breadhtml}</div>
<script type="text/javascript">
	setBread($('#tmpbread').html());
	//===========================
	$(function(){
		var type='{$cache.type}';
		if(type=='text'){
			$('.nr').show();
			$('#addtw').hide();
		}else if(type=='news'){
			$('.nr').hide();
			$('#addtw').hide();
			$('#dnrdiv').empty();
		}else if(type=='newss'){
			$('.nr').hide();
			$('#addtw').show();
			$('#dnrdiv').empty();
		}
	})
</script>

<!--表单验证与提交封装-->
<script type="text/javascript">
	$('#bbForm').bootstrapValidator({
		submitHandler: function (validator, form, submitButton) {
           var tourl="{:U('Admin/Wx/keyword_set')}";
           var data=$('#bbForm').serialize();
           $.bb.ajax('post',tourl,data,null);
           return false;
        },
	});
	//============================================
	var html='<div class="form-group">\
                    <label class="col-lg-2 control-label">图文标题</label>\
                    <div class="col-lg-4">\
                    	<input type="text" class="form-control" name="data[title][]" data-bv-field="data[title][]" >\
                   		<i class="form-control-feedback" data-bv-field="data[title][]" style="display: none;"></i>\
                   </div>\
               </div>\
               <div class="form-group">\
                    <label class="col-lg-2 control-label">图文图片</label>\
                    <div class="col-lg-4">\
                    	<div class="input-group input-group-sm">\
                    		<input type="text" class="form-control" name="data[img][]" data-bv-field="data[img][]" id="bb-img">\
                    		<i class="form-control-feedback" data-bv-field="data[img][]" style="display: none;"></i>\
                    		<span class="input-group-btn">\
                        		<button class="btn btn-default shiny" type="button" onclick="Imgviewer(\'bb-img\')"><i class="fa fa-camera-retro"></i>预览</button><button class="btn btn-default shiny" type="button" onclick="Imguploader(\'bb-img\',false)"><i class="glyphicon glyphicon-picture"></i>上传</button>\
                    		</span>\
                    	</div>\
                    </div>\
              </div>\
               <div class="form-group">\
                    <label class="col-lg-2 control-label">图文详情</label>\
                    <div class="col-lg-4">\
                    	<input type="text" class="form-control" name="data[info][]" data-bv-field="data[info][]">\
                    	<i class="form-control-feedback" data-bv-field="data[info][]" style="display: none;"></i>\
                    </div>\
               </div>\
               <div class="form-group">\
                    <label class="col-lg-2 control-label">图文链接</label>\
                    <div class="col-lg-4">\
                    	<input type="text" class="form-control" name="data[url][]" data-bv-field="data[url][]" >\
                    	<i class="form-control-feedback" data-bv-field="data[url][]" style="display: none;"></i>\
                    </div>\
               </div>';
	//============================================
	$('#typechange').change(function(){ 
		var v=$(this).children('option:selected').val();
		if(v=='text'){
			$('.nr').show();
			$('#addtw').hide();
		}else if(v=='news'){
			$('.nr').hide();
			$('#addtw').hide();
			$('#dnrdiv').empty();
			$('#dnrdiv').append(html);
		}else if(v=='newss'){
			$('.nr').hide();
			$('#addtw').show();
			$('#dnrdiv').empty();
		}
	});
	
	//==================
	$('#addtw').on('click',function(){
		$('#dnrdiv').append('<hr/>');
		$('#dnrdiv').append(html);
		return false;
	});
	
</script>

<!--/表单验证与提交封装-->